import Taro from '@tarojs/taro';

export const toast = (title: string, isNoMask?: boolean) => {
  Taro.showToast({
    title,
    icon: 'none',
    mask: !isNoMask,
  });
};

export const confirm = (
  content: string,
  confirmCb: () => void,
  title?: string,
  cancelCb?: () => void
) => {
  return new Promise((resolve, reject) => {
    Taro.showModal({
      title: title || '提示',
      content,
      confirmColor: '#177FFF',
      success: (res) => {
        if (res.confirm) {
          confirmCb();
          resolve('confirm')
        } else if (res.cancel) {
          cancelCb && cancelCb();
          reject('reject')
        }
      },
    });
  });
};
